package de.osmembrane.tools.xmlocalizr;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;

public class SelectLangDialog extends JDialog {

	private static final long serialVersionUID = 4381822380717615511L;
	
	private JComboBox upper, lower;	
	
	public SelectLangDialog() {
		setTitle(I18N.getString("SelectLangDialog.Title")); //$NON-NLS-1$
		
		setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.insets = new Insets(8, 8, 8, 8);		
		
		String[] locs = new String[Locale.getAvailableLocales().length];
		for (int i = 0; i < Locale.getAvailableLocales().length; i++) {
			locs[i] = Locale.getAvailableLocales()[i].getLanguage();
		}
		
		gbc.gridx = 0;
		gbc.gridy = 0;
		add(new JLabel(I18N.getString("SelectLangDialog.TopLang")), gbc); //$NON-NLS-1$
		
		gbc.gridx = 1;
		upper = new JComboBox(locs);
		upper.setSelectedItem("en"); //$NON-NLS-1$
		add(upper, gbc);
		
		gbc.gridx = 0;
		gbc.gridy = 1;
		add(new JLabel(I18N.getString("SelectLangDialog.BottomLang")), gbc); //$NON-NLS-1$
		
		gbc.gridx = 1;
		lower = new JComboBox(locs);
		lower.setSelectedItem(Locale.getDefault().getLanguage());
		add(lower, gbc);
		
		gbc.gridx = 0;
		gbc.gridy = 2;
		gbc.gridwidth = 2;
		JButton okBtn = new JButton(I18N.getString("SelectLangDialog.OK")); //$NON-NLS-1$
		okBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
			}
		});
		add(okBtn, gbc);
		
		setModal(true);
		
		pack();
		XMLocalizr.centerWindow(this);
	}
	
	public String getUpperLang() {
		return (String) upper.getSelectedItem();
	}
	
	public String getLowerLang() {
		return (String) lower.getSelectedItem();
	}

}
